﻿namespace HtERP.Data
{
    public class CreateData
    {
        public string CreateDatabase()
        {
            //建库：如果不存在创建数据库存在不会重复创建
            HtTestdb.db.DbMaintenance.CreateDatabase();
            string aaa = "数据库已经创建,请初始化数据";
            return aaa;
        }
        public string InitializeData()
        {
            string aaa = "初始化未完成";
            if (HtTestdb.db.Ado.IsValidConnection())
            {
                HtTestdb.db.CurrentConnectionConfig.MoreSettings.IsCorrectErrorSqlParameterName = true; //局部生效兼容模式
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("员工", false))
                {
                    //创建员工表
                    HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(员工));
                    //插入超级管理员
                    HtTestdb.db.Insertable(new 员工() { 姓名 = "admin", 手机 = "123456789", 密码 = "e10adc3949ba59abbe56e057f20f883e", 住宅电话 = "123456", QQ号 = "12345678", 电子邮件 = "12@56.78", 地址 = "中国", 部门 = "总务", 头衔 = " ", 雇佣日期 = DateTime.Now, 身份证号 = " ", 是否为管理员 = true, 是否已离职 = false, 超级管理员 = true, 账户余额 = 88 }).ExecuteCommand();
                    //插入普通员工
                    HtTestdb.db.Insertable(new 员工() { 姓名 = "user", 手机 = "234567890", 密码 = "e10adc3949ba59abbe56e057f20f883e", 住宅电话 = "123456", QQ号 = "12345678", 电子邮件 = "12@56.78", 地址 = "中国", 部门 = "设计制作", 头衔 = " ", 雇佣日期 = DateTime.Now, 身份证号 = " ", 是否为管理员 = false, 是否已离职 = false, 超级管理员 = false, 账户余额 = 66 }).ExecuteCommand();
                }
                //建表
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("收款账单")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(收款账单));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("数码印刷工作表")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(数码印刷工作表));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("CTP制作输出表")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(CTP制作输出表));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("菲林制作输出表")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(菲林制作输出表));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("纯设计制作")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(纯设计制作));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("后道加工")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(后道加工));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("纸张类型")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(纸张类型));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("客户")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(客户));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("CTP板材型号")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(CTP板材型号));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("CTP加网线数")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(CTP加网线数));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("CTP网点类型")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(CTP网点类型));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("CTP印刷机咬口要求")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(CTP印刷机咬口要求));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("数码印刷费率表")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(数码印刷费率表));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("公用设置"))
                {
                    HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(公用设置));
                    HongtengDbCon.Db.Insertable(new 公用设置() { 菲林起步价 = 5, 菲林每平米价格=150, 资源费每张价格=2, 数码打样每平米价格=100, CTP每平米价格=50, 切割每米价格=(decimal)0.5, 默认折扣方案= "1" }).ExecuteReturnEntity();

                }
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("支出部门"))
                {
                    HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(支出部门));
                    HongtengDbCon.Db.Insertable(new 支出部门() { 部门 = "总务"}).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出部门() { 部门 = "设计制作" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出部门() { 部门 = "菲林CTP" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出部门() { 部门 = "印刷打印" }).ExecuteReturnEntity();
                }
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("支出类别")) 
                {
                    HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(支出类别));
                    HongtengDbCon.Db.Insertable(new 支出类别() { 类别 = "房租水电" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出类别() { 类别 = "工资奖金" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出类别() { 类别 = "日常办公" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出类别() { 类别 = "机器设备" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出类别() { 类别 = "打印耗材" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出类别() { 类别 = "纸张" }).ExecuteReturnEntity();
                    HongtengDbCon.Db.Insertable(new 支出类别() { 类别 = "菲林板材" }).ExecuteReturnEntity();
                }
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("支出总表")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(支出总表));
                if (!HtTestdb.db.DbMaintenance.IsAnyTable("彩喷写真工作表")) HtTestdb.db.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(彩喷写真工作表));

                aaa = "数据初始化完成";
            }
            else
            {
                aaa = "请先创建数据库，再初始化数据";
            }
            return aaa;
        }
    }
}
